 <!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="assets/css/stylesheet.css">
<link rel="stylesheet" type="text/css" href="assets/css/fontawesome.min.css">

<title>SAT>IP - Frontend info Page</title>

<script src="assets/js/menu.js"></script>
<script src="assets/js/loadxmldoc.js"></script>
<script src="assets/js/postxmldoc.js"></script>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/addtableentry.js"></script>
<script src="assets/js/utils.js"></script>
<script src="assets/js/popper.min.js"></script>
<script>
	var autoload = 1;
	var content;
	var once = 0;

	function buildNavContent(xmlDoc) {
		var page = "";
		var streams = xmlDoc.getElementsByTagName("streamindex");
		if (streams.length > 0) {
			var visibleStream = xmlDoc.getElementsByTagName(content)[0];
			var streamID = content + " ";

			page += "<table class=\"table table-bordered table-sm\">";
			page += "<thead></thead>";
			page += "<tbody>";

			page += "<tr class=\"separator bg-info\"><th colspan=\"" + (streams.length + 1) + "\">Frontend Info</th></tr>";

			page += addTableLineEntry("Stream Index", xmlDoc, streamID + "streamindex");

			page += addTableLineEntry("Enable", xmlDoc, streamID + "enable");
			page += addTableLineEntry("Attached", xmlDoc, streamID + "attached");
			page += addTableLineEntry("Type", xmlDoc, streamID + "type");
			page += addTableLineEntry("Name", xmlDoc, streamID + "frontendname");
			page += addTableLineEntry("Path", xmlDoc, streamID + "pathname");
			page += addTableLineEntry("Freq Range", xmlDoc, streamID + "freq");
			page += addTableLineEntry("Symbol Rate Range", xmlDoc, streamID + "symbol");
			page += addTableLineEntry("Linux DVB API version", xmlDoc, streamID + "dvbversion");

			page += "<tr class=\"separator bg-info\"><th colspan=\"" + (streams.length+1) + "\">Stream Info</th></tr>";
			page += addTableLineURL("Stream URL", buildStreamURL(xmlDoc, streamID));
			page += addTableLineEntry("Owner", xmlDoc, streamID + "owner");
			page += addTableLineEntry("RTP Port", xmlDoc, streamID + "rtpPort");
			page += addTableLineEntry("RTCP Port", xmlDoc, streamID + "rtcpPort");
			page += addTableLineEntry("HTTP Port", xmlDoc, streamID + "httpPort");
			page += addTableLineEntry("Session ID", xmlDoc, streamID + "ownerSessionID");
			page += addTableLineEntry("User-Agent", xmlDoc, streamID + "userAgent");
			page += addTableLineEntry("RTP packet count", xmlDoc, streamID + "spc");
			page += addTableLineEntry("RTP streamed (MB)", xmlDoc, streamID + "payload");

			var freq = visibleStream.getElementsByTagName("tunefreq");
			if (freq.length > 0) {
				page += "<tr class=\"separator bg-info\"><th colspan=\"" + (streams.length+1) + "\">Channel Info</th></tr>";

				page += addTableLineEntry("Network Name", xmlDoc, streamID + "networkname");
				page += addTableLineEntry("Channel Name", xmlDoc, streamID + "channelname");

				page += addTableLineEntry("Delivery System", xmlDoc, streamID + "delsys");

				page += addTableLineEntry("Tune Frequency (kHz)", xmlDoc, streamID + "tunefreq");
				page += addTableLineEntry("Modulation", xmlDoc, streamID + "modulation");
				page += addTableLineEntry("Fec", xmlDoc, streamID + "fec");
				page += addTableLineEntry("Symbol Rate", xmlDoc, streamID + "tunesymbol");
				page += addTableLineEntry("Rolloff", xmlDoc, streamID + "rolloff");
				page += addTableLineEntry("Source", xmlDoc, streamID + "src");
				page += addTableLineEntry("Polarization", xmlDoc, streamID + "pol");

				page += "<tr class=\"separator bg-info\"><th colspan=\"" + (streams.length+1) + "\">Monitor Info</th></tr>";
				page += addTableLineEntry("Status", xmlDoc, streamID + "status");
				page += addTableLineEntry("Signal Strength", xmlDoc, streamID + "signal");
				page += addTableLineEntry("snr", xmlDoc, streamID + "snr");
				page += addTableLineEntry("ber", xmlDoc, streamID + "ber");
				page += addTableLineEntry("unc", xmlDoc, streamID + "unc");
			}
			var filter = visibleStream.getElementsByTagName("filter");
			if (filter.length > 0) {
				page += addTableLineEntry("PID", xmlDoc, streamID + "pidcsv");
				page += addTableLineEntry("CC Errors", xmlDoc, streamID + "totalCCErrors");
			}

			page += "<tr class=\"separator bg-info\"><th colspan=\"" + (streams.length+1) + "\">Configuration</th></tr>";
			page += addTableLineEntry("DVR Buffer (MB)", xmlDoc, streamID + "dvrbuffer");
			page += addTableLineEntry("RTCP Signal Update Freq", xmlDoc, streamID + "rtcpSignalUpdate");
			page += addTableLineEntry("Internal Software Pid Filtering", xmlDoc, streamID + "internalPidFiltering");
			page += addTableLineEntry("Filter PCR for timing", xmlDoc, streamID + "filterPCR");
			page += addTableLineEntry("Wait On Tuning Lock Timeout (ms)", xmlDoc, streamID + "waitOnLockTimeout");
			page += addTableLineEntry("Force Old Styte Signal Status", xmlDoc, streamID + "forceOldStyleStatus");
			page += addTableLineEntry("Turn off LNB Voltage during teardown", xmlDoc, streamID + "turnoffLNBPower");
			page += addTableLineEntry("Enable slightly higher LNB Voltage", xmlDoc, streamID + "higherLnbVoltage");
			page += addTableLineEntry("List of PIDs to add to requests (CSV)", xmlDoc, streamID + "addUserPids");
			page += addTableLineEntry("Maximum DVBCSA Batch Size", xmlDoc, streamID + "dvbcsa_bs_batch_size");
			page += addTableLineEntry("ICAM enabled in libdvbcsa", xmlDoc, streamID + "icamEnabled");

			var transformation = visibleStream.getElementsByTagName("transformation");
			if (transformation.length > 0) {
				page += "<tr class=\"separator bg-info\"><th colspan=\"" + (streams.length+1) + "\">Transformation Info</th></tr>";
				page += addTableLineEntry("Transformation enable", xmlDoc, streamID + "transformEnable");
				page += addTableLineEntry("Advertise as", xmlDoc, streamID + "advertiseAsType");
				page += addTableLineEntry("Transformation Mapping M3U", xmlDoc, streamID + "transformM3U");
				page += addTableLineEntry("Transformation Frequency", xmlDoc, streamID + "transformFreq");
			}

			var fbc = visibleStream.getElementsByTagName("fbc");
			if (fbc.length > 0) {
				page += "<tr class=\"separator bg-info\"><th colspan=\"" + (streams.length+1) + "\">FBC Configuration</th></tr>";
				page += addTableLineEntry("FBC Input Connection", xmlDoc, streamID + "fbcConnection");
				page += addTableLineEntry("FBC Linked", xmlDoc, streamID + "fbcLinked");
				page += addTableLineEntry("Send DiSEqC Via Linked Root Tuner", xmlDoc, streamID + "sendDiSEqcViaRootTuner");
				page += addTableLineEntry("FBC Tuner Connected to", xmlDoc, streamID + "fbcConnectionRaw");
				page += addTableLineEntry("FBC Tuner Slot Offset", xmlDoc, streamID + "fbcTunerSlotOffset");
			}

			var diseqcType = visibleStream.getElementsByTagName("diseqcType");
			if (diseqcType.length > 0) {
				page += "<tr class=\"separator bg-info\"><th colspan=\"" + (streams.length+1) + "\">DiSEqC Configuration</th></tr>";
				page += addTableLineEntry("DiSEqC", xmlDoc, streamID + "diseqcType");
				var diseqc = visibleStream.getElementsByTagName("diseqc");
				if (diseqc.length > 0) {
					page += addTableLineEntry("Switch Type", xmlDoc, streamID + "switchType");
					page += addTableLineEntry("Number of Switch Inputs", xmlDoc, streamID + "numberOfInputs");
					page += addTableLineEntry("Repeat DiSEqC", xmlDoc, streamID + "diseqc_repeat");
					page += addTableLineEntry("Channel Freq (MHz)", xmlDoc, streamID + "chFreq");
					page += addTableLineEntry("Channel Slot (0-32)", xmlDoc, streamID + "chSlot");
					page += addTableLineEntry("Delay before write", xmlDoc, streamID + "delayBeforeWrite");
					page += addTableLineEntry("Delay after write", xmlDoc, streamID + "delayAfterWrite");
					page += addTableLineEntry("PIN (256 disabled)", xmlDoc, streamID + "pin");
				}
			}
			var lnb = visibleStream.getElementsByTagName("lnbtype");
			if (lnb.length > 0) {
				page += "<tr class=\"separator bg-info\"><th colspan=\"" + (streams.length+1) + "\">LNB Configuration</th></tr>";
				for (var i = 1; i <= lnb.length; i++) {
					page += "<tr class=\"\"><th colspan=\"" + (streams.length+1) + "\">LNB " + i + "</th></tr>";
					var lnbt = streamID + "lnb" + i + " ";
					page += addTableLineEntry("Lof High (MHz)", xmlDoc, lnbt + "lofHigh");
					page += addTableLineEntry("Lof Low (MHz)", xmlDoc, lnbt + "lofLow");
					page += addTableLineEntry("Lof Switch (MHz)", xmlDoc, lnbt + "lofSwitch");
				}
			}
			page += "</tbody>";
			page +=	 "</table>";
		}
		return page;
	}

	function createNavTab(xmlDoc) {
		var tab = "";
		var streams = xmlDoc.getElementsByTagName("streamindex");
		if (streams.length > 0) {
			var len = streams.length;
			tab += "<ul class=\"nav nav-tabs\">";
			for (en = 1; en <= len; en++) {
				var streamIndex = xmlDoc.querySelector("stream" + en + " " + "streamindex").innerHTML;
				tab += "<li class=\"nav-item\"><a class=\"nav-link";
				if (en == 1) {
					tab += " active";
				}
				tab += "\" data-toggle=\"tab\" href=\"#stream" + streamIndex + "\">Frontend " + streamIndex + "</a></li>"
			}
			tab += "</ul>";
			tab += "<div class=\"tab-content border rounded-bottom\" >";
			tab += "<div id=\"stream" + "\" class=\"tab-pane fade show active\"></div>";
			tab += "</div>";
		}
		return tab;
	}

	function updatePage() {
		loadXMLDoc("SatPI.xml");
	}

	// function called when xml is loaded
	function xmlloaded(xml) {
		if (once == 0) {
			once = 1;
			document.getElementById("tableContent").innerHTML = createNavTab(xml);
			$(".nav-tabs a").on("shown.bs.tab", function(event) {
				var href = $(event.target).attr("href");
				// remove # from href
				content = href.substr(1, href.length);
				updatePage();
			});
			// check if we have #stream2
			var hash = location.hash;
			if (hash.length > 0) {
				// remove # from URL hash
				content = hash.substr(1, hash.length);
				var showTab = '.nav-tabs a[href="' + hash + '"]';
				$(showTab).tab('show');
				updatePage();
			} else {
				content = 'stream1';
			}
		}
		if (autoload == 1) {
			document.getElementById("stream").innerHTML = buildNavContent(xml);
		}
	}

	$(document).ready(function(){
		$('[data-toggle="tooltip"]').tooltip();
	});

</script>

</head>
<body>
<div id="menu"></div>

<div class="window-start container border rounded-bottom">
	<div class="window-name">
		<p>Frontend Info</p>
	</div>
	<div class="p-1 table-responsive table-text-size" id="tableContent"></div>
	<script>
		// make menu
		document.getElementById("menu").innerHTML = buildmenu();
		setMenuItemActive("frontend");

		updatePage();

		// Call the ajax refresh each refresh_time seconds
		var refresh_time = 2000;
		setInterval("updatePage()", refresh_time);
	</script>
</div>

</body>
</html>
